import {
    BASE_URL
} from "../constants/index.js";
// 全局请求封装
//const token = '';//自己的token令牌，最好读取缓存中的
const token = uni.getStorageSync('appToken')
const apiUrl = BASE_URL;
//const header={'appToken':token}

const baseRequest = (url,method,params) => {
	if(params!=null && typeof(params)!="undefined"){
		header["Content-Type"]="application/x-www-form-urlencoded";
	}
	
	return new Promise((resolve, reject) => {
		uni.request({
			url: apiUrl + url,
			data:params,
			method:method,
			header:header
		}).then((response)=>{
			let [error, res] = response;
			resolve(res.data);
			//console.log(response[1].header.token); //获取请求头token
		}).catch(error => {
            let [err, res] = error;
            reject(err)
        })
	 });
}

export default {
	baseRequest
}